package com.xlf.controller.client;

import com.xlf.service.OrderService;
import com.xlf.utils.ResponseResult;
import com.xlf.vo.AddOrderVO;
import com.xlf.vo.QueryPageBean;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 用户订单模块
 */
@Tag(name = "用户订单模块")
@RestController
@RequestMapping("/client/auth/order")
public class ClientOrderController {

    @Resource
    OrderService orderService;

    /**
     * 添加订单
     * @param addOrderVO    新增订单VO对象
     * @return              执行结果
     */
    @Operation(summary = "添加订单")
    @PostMapping("/addOrder")
    public ResponseResult addOrder(@RequestBody AddOrderVO addOrderVO){
        return ResponseResult.success("下单成功",orderService.addOrder(addOrderVO));
    }

    /**
     * 条件查询订单数据，支持分页、时间区间、分类/标签id查询
     * @param queryPageBean 分页查询条件对象
     * @return              分页查询结果
     */
    @Operation(summary = "条件查询订单数据", description = "支持分页、时间区间、分类/标签id查询")
    @PostMapping("/getOrderPage")
    public ResponseResult getOrderPage(@RequestBody QueryPageBean queryPageBean){
        return ResponseResult.success("获取订单分页成功",orderService.getClientOrderPage(queryPageBean));
    }

    /**
     * 通过订单id拿订单
     * @param id    订单id
     * @return      订单id对应的数据
     */
    @Operation(summary = "通过订单id拿订单")
    @GetMapping("/getOrderById/{id}")
    public ResponseResult getOrderById(@PathVariable(value = "id") Long id){
        return ResponseResult.success("通过id获取订单成功",orderService.getClientOrderById(id));
    }
}
